package com.yanqu.road.entity.activity.hsisland.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_c_activity_hs_island_user_data")
public class HsIslandUserData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "分组ID", select = true, update = true)
    private int groupId;

    @FieldTypeAnnotation(desc = "玩家ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "玩家区服ID")
    private long serverId;

    @FieldTypeAnnotation(desc = "商会ID")
    private String unionId;

    @FieldTypeAnnotation(desc = "基础魂力")
    private long power;

    @FieldTypeAnnotation(desc = "形象ID")
    private int imageId;

    @FieldTypeAnnotation(desc = "已解锁的形象IDS")
    private Set<Integer> unlockedImageIds;

    @FieldTypeAnnotation(desc = "体力")
    private int energy;

    @FieldTypeAnnotation(desc = "体力恢复时间")
    private long energyRestoreTime;

    @FieldTypeAnnotation(desc = "积分")
    private long score;

    @FieldTypeAnnotation(desc = "当前所在层ID")
    private int floorId;

    @FieldTypeAnnotation(desc = "当前所在岛ID")
    private int islandId;

    @FieldTypeAnnotation(desc = "当前所在岛x坐标")
    private int x;

    @FieldTypeAnnotation(desc = "当前所在岛y坐标")
    private int y;

    @FieldTypeAnnotation(desc = "协助次数")
    private int helpNum;

    @FieldTypeAnnotation(desc = "每消耗N1体力恢复N2【协助次数】的计数器")
    private int helpNumCount;

    @FieldTypeAnnotation(desc = "PVE可被邀请次数")
    private int canPveInviteNum;

    @FieldTypeAnnotation(desc = "每消耗N1体力恢复N2【PVE可被邀请次数】的计数器")
    private int canPveInviteNumCount;

    @FieldTypeAnnotation(desc = "buffMap")
    private Map<Integer, HsIslandBuffData> buffMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "门客MAP")
    private Map<Integer, HsIslandPatronsData> patronsMap;

    @FieldTypeAnnotation(desc = "战场id")
    private long battleFieldId;

    @FieldTypeAnnotation(desc = "精力值")
    private long pvpEnergy;

    @FieldTypeAnnotation(desc = "精力值恢复时间")
    private long pvpEnergyLastTime;

    @FieldTypeAnnotation(desc = "上次攻击怪物时间")
    private long lastAttackMonsterTime;

    @FieldTypeAnnotation(desc = "上次攻击玩家时间")
    private long lastAttackPlayerTime;

    @FieldTypeAnnotation(desc = "上次攻击玩家时间")
    private long lastAttackBossTime;

    @FieldTypeAnnotation(desc = "已领奖的战场奖励")
    private List<Long> hadRewardBattleFieldIdList = new ArrayList<>();

    @FieldTypeAnnotation(desc = "活跃时间")
    private long activeTime;

    @FieldTypeAnnotation(desc = "捐献过的次数")
    private long donateNum;

    @FieldTypeAnnotation(desc = "可双倍捐献的次数")
    private int dUsableDonateNum;

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public HsIslandUserData() {
    }

    public HsIslandUserData(int activityId, int groupId, long userId, long serverId, String unionId, int imageId, int energy, int floorId, int islandId, int x, int y, int helpNum, int canPveInviteNum, Map<Integer, HsIslandPatronsData> patronsMap, long pvpEnergy, int dUsableDonateNum) {
        this.activityId = activityId;
        this.groupId = groupId;
        this.userId = userId;
        this.serverId = serverId;
        this.unionId = unionId;
        this.imageId = imageId;
        this.energy = energy;
        this.energyRestoreTime = 0;
        this.score = 0;
        this.floorId = floorId;
        this.islandId = islandId;
        this.x = x;
        this.y = y;
        this.helpNum = helpNum;
        this.helpNumCount = 0;
        this.canPveInviteNum = canPveInviteNum;
        this.canPveInviteNumCount = 0;
        this.patronsMap = patronsMap;
        this.createTime = System.currentTimeMillis();
        this.pvpEnergy = pvpEnergy;
        this.pvpEnergyLastTime = 0;
        this.activeTime = System.currentTimeMillis();
        this.hadRewardBattleFieldIdList = new ArrayList<>();
        this.unlockedImageIds = new HashSet<>();
        this.unlockedImageIds.add(imageId);
        this.donateNum = 0;
        this.dUsableDonateNum = dUsableDonateNum;
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getGroupId() {
        return groupId;
    }
    public void setGroupId(int groupId) {
        if (this.groupId != groupId) {
            this.groupId = groupId;
            setOp(DataStatus.Update);
        }
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public long getServerId() {
        return serverId;
    }
    public void setServerId(long serverId) {
        if (this.serverId != serverId) {
            this.serverId = serverId;
            setOp(DataStatus.Update);
        }
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        if (null == unionId){
            return;
        }
        if (this.unionId == null || !this.unionId.equals(unionId)) {
            this.unionId = unionId;
            setOp(DataStatus.Update);
        }
    }

    public long getPower() {
        return power;
    }
    public void setPower(long power) {
        if (this.power != power) {
            this.power = power;
            setOp(DataStatus.Update);
        }
    }

    public int getImageId() {
        return imageId;
    }
    public void setImageId(int imageId) {
        if (this.imageId != imageId) {
            this.imageId = imageId;
            setOp(DataStatus.Update);
        }
    }

    public Set<Integer> getUnlockedImageIds() {
        return unlockedImageIds;
    }
    public void setUnlockedImageIds(Set<Integer> unlockedImageIds) {
        if (null == unlockedImageIds){
            return;
        }
        if (this.unlockedImageIds == null || !this.unlockedImageIds.equals(unlockedImageIds)) {
            this.unlockedImageIds = unlockedImageIds;
            setOp(DataStatus.Update);
        }
    }

    public void addUnlockedImageId(int imageId) {
        this.unlockedImageIds.add(imageId);
        setOp(DataStatus.Update);
    }

    public int getEnergy() {
        return energy;
    }
    public void setEnergy(int energy) {
        if (this.energy != energy) {
            this.energy = energy;
            setOp(DataStatus.Update);
        }
    }

    public long getEnergyRestoreTime() {
        return energyRestoreTime;
    }
    public void setEnergyRestoreTime(long energyRestoreTime) {
        if (this.energyRestoreTime != energyRestoreTime) {
            this.energyRestoreTime = energyRestoreTime;
            setOp(DataStatus.Update);
        }
    }

    public long getScore() {
        return score;
    }
    public void setScore(long score) {
        if (this.score != score) {
            this.score = score;
            setOp(DataStatus.Update);
        }
    }

    public synchronized void addScore(long score) {
        this.score += score;
        setOp(DataStatus.Update);
    }

    public int getFloorId() {
        return floorId;
    }
    public void setFloorId(int floorId) {
        if (this.floorId != floorId) {
            this.floorId = floorId;
            setOp(DataStatus.Update);
        }
    }

    public int getIslandId() {
        return islandId;
    }
    public void setIslandId(int islandId) {
        if (this.islandId != islandId) {
            this.islandId = islandId;
            setOp(DataStatus.Update);
        }
    }

    public int getX() {
        return x;
    }
    public void setX(int x) {
        if (this.x != x) {
            this.x = x;
            setOp(DataStatus.Update);
        }
    }

    public int getY() {
        return y;
    }
    public void setY(int y) {
        if (this.y != y) {
            this.y = y;
            setOp(DataStatus.Update);
        }
    }

    public int getHelpNum() {
        return helpNum;
    }
    public void setHelpNum(int helpNum) {
        if (this.helpNum != helpNum) {
            this.helpNum = helpNum;
            setOp(DataStatus.Update);
        }
    }

    public int getHelpNumCount() {
        return helpNumCount;
    }
    public void setHelpNumCount(int helpNumCount) {
        if (this.helpNumCount != helpNumCount) {
            this.helpNumCount = helpNumCount;
            setOp(DataStatus.Update);
        }
    }

    public int getCanPveInviteNum() {
        return canPveInviteNum;
    }

    public void setCanPveInviteNum(int canPveInviteNum) {
        if (this.canPveInviteNum != canPveInviteNum) {
            this.canPveInviteNum = canPveInviteNum;
            setOp(DataStatus.Update);
        }
    }

    public int getCanPveInviteNumCount() {
        return canPveInviteNumCount;
    }

    public void setCanPveInviteNumCount(int canPveInviteNumCount) {
        if (this.canPveInviteNumCount != canPveInviteNumCount) {
            this.canPveInviteNumCount = canPveInviteNumCount;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, HsIslandBuffData> getBuffMap() {
        return buffMap;
    }
    public void setBuffMap(Map<Integer, HsIslandBuffData> buffMap) {
        if (null == buffMap){
            return;
        }
        if (this.buffMap == null || !this.buffMap.equals(buffMap)) {
            this.buffMap = buffMap;
            setOp(DataStatus.Update);
        }
    }

    public HsIslandBuffData getBuff(int buffId) {
        return this.buffMap.get(buffId);
    }

    public synchronized void addBuff(int buffId, int buffTime) {
        HsIslandBuffData buff = this.buffMap.computeIfAbsent(buffId, k -> new HsIslandBuffData(buffId));
        buff.setTimes(buff.getTimes() + buffTime);
    }

    public Map<Integer, HsIslandPatronsData> getPatronsMap() {
        return patronsMap;
    }

    public void setPatronsMap(Map<Integer, HsIslandPatronsData> patronsMap) {
        if (null == patronsMap){
            return;
        }
        if (this.patronsMap == null || !this.patronsMap.equals(patronsMap)) {
            this.patronsMap = patronsMap;
            setOp(DataStatus.Update);
        }
    }

    public long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
        if (this.createTime != createTime) {
            this.createTime = createTime;
            setOp(DataStatus.Update);
        }
    }

    public long getBattleFieldId() {
        return battleFieldId;
    }

    public void setBattleFieldId(long battleFieldId) {
        if (this.battleFieldId != battleFieldId) {
            this.battleFieldId = battleFieldId;
            setOp(DataStatus.Update);
        }
    }

    public long getPvpEnergy() {
        return pvpEnergy;
    }

    public void setPvpEnergy(long pvpEnergy) {
        if (this.pvpEnergy != pvpEnergy) {
            this.pvpEnergy = pvpEnergy;
            setOp(DataStatus.Update);
        }
    }

    public long getPvpEnergyLastTime() {
        return pvpEnergyLastTime;
    }

    public void setPvpEnergyLastTime(long pvpEnergyLastTime) {
        if (this.pvpEnergyLastTime != pvpEnergyLastTime) {
            this.pvpEnergyLastTime = pvpEnergyLastTime;
            setOp(DataStatus.Update);
        }
    }

    public long getLastAttackMonsterTime() {
        return lastAttackMonsterTime;
    }

    public void setLastAttackMonsterTime(long lastAttackMonsterTime) {
        if (this.lastAttackMonsterTime != lastAttackMonsterTime) {
            this.lastAttackMonsterTime = lastAttackMonsterTime;
            setOp(DataStatus.Update);
        }
    }

    public long getLastAttackPlayerTime() {
        return lastAttackPlayerTime;
    }

    public void setLastAttackPlayerTime(long lastAttackPlayerTime) {
        if (this.lastAttackPlayerTime != lastAttackPlayerTime) {
            this.lastAttackPlayerTime = lastAttackPlayerTime;
            setOp(DataStatus.Update);
        }
    }

    public long getLastAttackBossTime() {
        return lastAttackBossTime;
    }

    public void setLastAttackBossTime(long lastAttackBossTime) {
        if (this.lastAttackBossTime != lastAttackBossTime) {
            this.lastAttackBossTime = lastAttackBossTime;
            setOp(DataStatus.Update);
        }
    }

    public long getActiveTime() {
        return activeTime;
    }

    public void setActiveTime(long activeTime) {
        if (this.activeTime != activeTime) {
            this.activeTime = activeTime;
            setOp(DataStatus.Update);
        }
    }

    public List<Long> getHadRewardBattleFieldIdList() {
        return hadRewardBattleFieldIdList;
    }

    public void setHadRewardBattleFieldIdList(List<Long> hadRewardBattleFieldIdList) {
        if (hadRewardBattleFieldIdList == null) {
            return;
        }
        this.hadRewardBattleFieldIdList = hadRewardBattleFieldIdList;
    }

    public long getDonateNum() {
        return donateNum;
    }

    public void setDonateNum(long donateNum) {
        if (this.donateNum != donateNum) {
            this.donateNum = donateNum;
            setOp(DataStatus.Update);
        }
    }

    public int getDUsableDonateNum() {
        return dUsableDonateNum;
    }

    public void setDUsableDonateNum(int dUsableDonateNum) {
        if (this.dUsableDonateNum != dUsableDonateNum) {
            this.dUsableDonateNum = dUsableDonateNum;
            setOp(DataStatus.Update);
        }
    }
}
